package o;

import android.text.TextUtils;
import com.huawei.appgallery.downloadengine.api.DownloadChkInfo;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.deamon.bean.StartDownloadResponse;
import java.util.List;

public class dvu implements IServerCallBack {
    private SessionDownloadTask ˋ;

    public dvu(SessionDownloadTask sessionDownloadTask) {
        this.ˋ = sessionDownloadTask;
    }

    public void ˏ() {
        if (this.ˋ != null && this.ˋ.ـ() == 0 && !TextUtils.isEmpty(this.ˋ.ॱˋ())) {
            cvt o_dvo = new dvo(this.ˋ);
            if (this.ˋ.ˌ() == 4) {
                o_dvo.setBlockIfProtocolNotAgreed(false);
            }
            cfw.ˎ(o_dvo, this);
        }
    }

    public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        if (responseBean.getResponseCode() == 0 && (responseBean instanceof StartDownloadResponse)) {
            StartDownloadResponse startDownloadResponse = (StartDownloadResponse) responseBean;
            dvo o_dvo = (dvo) o_cvu;
            if (o_dvo == null || TextUtils.isEmpty(o_dvo.pkgName_)) {
                Logger.e("DownloadStartReporter", "req is null or req.pkgName_ is null");
                return;
            }
            SessionDownloadTask ˋ = dvt.ˏ().ˋ(o_dvo.pkgName_);
            if (ˋ == null) {
                Logger.e("DownloadStartReporter", "task is null");
            } else if (!ˋ.ꜟ() && !TextUtils.isEmpty(startDownloadResponse.appProfileUrl_) && !TextUtils.isEmpty(startDownloadResponse.profileSha256_)) {
                fhz ˋ2 = fho.ˏ().ˋ("PackageManager");
                if (ˋ2 != null) {
                    cnt o_cnt = (cnt) ˋ2.ॱ(cnt.class);
                    if (o_cnt != null) {
                        o_cnt.ˊ(ContentManager.getInstant().getContext(), o_dvo.pkgName_, o_dvo.versionCode, startDownloadResponse.appProfileUrl_, startDownloadResponse.profileSha256_);
                    }
                }
            }
        }
    }

    public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
        if (responseBean.getResponseCode() == 0 && (responseBean instanceof StartDownloadResponse)) {
            dvo o_dvo = (dvo) o_cvu;
            List list = ((StartDownloadResponse) responseBean).sliceCheckInfoSha256_;
            if (o_dvo != null && !TextUtils.isEmpty(o_dvo.pkgName_)) {
                SessionDownloadTask ˋ = dvt.ˏ().ˋ(o_dvo.pkgName_);
                if (ˋ != null) {
                    ˋ.ˊॱ(1);
                    Logger.ˎ("DownloadStartReporter", "DownloadStart is reported, package: " + ˋ.ˊˊ());
                    if (!ˋ.ꜟ() && list != null && !list.isEmpty()) {
                        int i = 0;
                        while (i < list.size()) {
                            try {
                                String[] split = ((DownloadChkInfo) list.get(i)).ˊ().split("-");
                                if (split.length == 2) {
                                    ((DownloadChkInfo) list.get(i)).ˏ(Long.parseLong(split[0]));
                                    ((DownloadChkInfo) list.get(i)).ˋ(Long.parseLong(split[1]));
                                    ((DownloadChkInfo) list.get(i)).ॱ(0);
                                }
                                i++;
                            } catch (Exception e) {
                                Logger.ˋ("DownloadStartReporter", "notifyResult" + e.toString());
                                return;
                            }
                        }
                        if (ˋ.ᐝˊ().get(0) != null) {
                            ((SplitTask) ˋ.ᐝˊ().get(0)).ˋ(list);
                        } else {
                            Logger.e("DownloadStartReporter", "task.getSplitTaskList().get(0) is null");
                        }
                    }
                }
            }
        }
    }
}
